package com.tzy.note.base.thread.state;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 模拟倒计时
 * 打印当前时间
 */
public class TestSleep_Demo{
    public static void main(String[] args) throws Exception{
        countDown();
        printTime();
    }
    //模拟10秒倒计时
    static void countDown() throws InterruptedException {
        int time = 10;
        while (time > 0 && time <= 10){
            Thread.sleep(1000);
            time--;
            System.out.println(time);
        }
    }

    //打印当前时间
    static void printTime(){
        while (true){
            try {
                Date startTime  = new Date(System.currentTimeMillis());
                System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(startTime));
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
